<?php

namespace app\admin\controller;

use app\admin\model\Orderconf;

class Orderconfig extends Base
{
    public function index(){
        $tenantId = session('TENANT_ID');
        $orderconf = Orderconf::get($tenantId);
        if($orderconf){
            $this->assign('invalid_time',$orderconf->invalid_time);
            $this->assign('confirm_time',$orderconf->confirm_time);
        }else{
            $this->assign('invalid_time',0);
            $this->assign('confirm_time',0);
        }
        $this->assign('tenantId',$tenantId);

        if(request()->isPost()){
            if($orderconf){
                $orderconf->invalid_time = input('post.invalid_time');
                $orderconf->confirm_time = input('post.confirm_time');
                $orderconf->save();
                return show(config('status.SUCCESS_STATUS'),'修改成功','修改成功');
            }else{
                $orderconf = new Orderconf();
                $orderconf->tenantId = input('post.tenantId');
                $orderconf->invalid_time = input('post.invalid_time');
                $orderconf->confirm_time = input('post.confirm_time');
                $orderconf->save();
                return show(config('status.SUCCESS_STATUS'),'添加成功','添加成功');
            }

        }

        return $this->fetch('order/config');
    }
}